﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Admin_DevMan_Query : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
       string pnum = Fnum.Text.Trim();
        string proname = FName.Text.Trim();
        string danwei = FDanwei.Text.Trim();
        string dutyname = FDutyName.Text.Trim();
        string condition = FCondition.Text.Trim();

        string pronum = "";
        pronum = Request.QueryString["num"].ToString();

        string tabelall = "<table class='layui-table' width='80%'><thead><tr><th>设备编号</th><th>设备名称</th><th>所属单位</th><th>责任人</th><th>放置位置</th><th>购置日期</th><th>仪器状况</th><th>操作</th></tr></thead>";
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        try
        {
            conn.Open();

            //删除记录
            SqlCommand cmddel = new SqlCommand();
            string SQLdel = "update Products set flag=0 where (pro_num=@pro_num)";
            cmddel.Connection = conn;
            cmddel.CommandText = SQLdel;
            cmddel.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter ppro_num = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            ppro_num.Value = pronum;
            cmddel.Parameters.Add(ppro_num);
            cmddel.ExecuteNonQuery();

            SqlCommand cmd = new SqlCommand();
            string SQL = "SELECT [pro_num], [pro_name], [pro_danwei], [auditor], [pro_location], [buydate], [condition] FROM [Products] WHERE (([pro_name] LIKE '%' + @pro_name + '%') AND ([pro_danwei] LIKE '%' + @pro_danwei + '%') AND ([auditor] LIKE '%' + @auditor + '%') AND ([pro_num] LIKE '%' + @pro_num + '%') AND ([condition] LIKE '%' + @condition + '%') and flag=1)";
            cmd.Connection = conn;
            cmd.CommandText = SQL;
            cmd.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter ppronum = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            ppronum.Value = pnum;
            cmd.Parameters.Add(ppronum);
            SqlParameter pname = new SqlParameter("@pro_name", SqlDbType.NVarChar, 20);
            pname.Value = proname;
            cmd.Parameters.Add(pname);
            SqlParameter ppdanwei = new SqlParameter("@pro_danwei", SqlDbType.NVarChar, 20);
            ppdanwei.Value = danwei;
            cmd.Parameters.Add(ppdanwei);
            SqlParameter pauditor = new SqlParameter("@auditor", SqlDbType.NVarChar, 10);
            pauditor.Value = dutyname;
            cmd.Parameters.Add(pauditor);
            SqlParameter pcondition = new SqlParameter("@condition", SqlDbType.NVarChar, 10);
            pcondition.Value = condition;
            cmd.Parameters.Add(pcondition);

            int k = 0;
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                int fieldcount = reader.FieldCount;      //取字段总数
                if (!reader.HasRows)            //有数据  ---行
                {
                    Label1.Text = "<table class='layui-table' style='width: 70%; margin-left:15% '><tr><td>没有数据</td></tr>";
                }
                else
                {
                    string trd = "<tbody>";                     //存储数据
                    while (reader.Read())               //当有数据可读时
                    {
                        trd += "<tr>";         //数据行开始，行以tr起
                        for (int i = 0; i < fieldcount; i++)
                        {   //每一列的内容
                            trd += "<td>" + reader[i].ToString() + "</td>";
                        }
                        /*  trd += "<td><a title = '查看详细信息' href = 'Admin_DevMan_Details.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe60b;</i></a>&nbsp;&nbsp;&nbsp;<a title='删除' name='getTableContent' onclick='getTableContent(this)'><i class='layui-icon'>&#xe640;</i></td></tr>";      */      //行结束
                        trd += "<td><a title = '查看详细信息' href = 'Admin_DevMan_Details.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe60b;</i></a>&nbsp;&nbsp;&nbsp;<a title='删除'  href = 'Admin_DevMan_Query.aspx?num=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe640;</i></td></tr>";
                        k = k + 1;
                    }
                    //Response.Write(tabelall + trd + "</tbody></table>");

                    Label1.Text = tabelall + trd + "</tbody></table>";
                    //MsgNum.Text = k.ToString();

                }
            }
        }


        finally
        {
            conn.Close();
        }

    }
}